<template>
  <el-dialog :title="!form.id ? '新增' : '修改'" :visible.sync="visible" :close-on-click-modal="false" width="70%">
    <el-form :model="form" label-width="120px" ref="dataForm">
      <el-row>
        <el-col :xs="24" :sm="12" :md="8">
          <el-form-item label="用户名" prop="username" :rules="rules.isRange('1-50')">
            <el-input v-model="form.username" placeholder="请输入用户名" maxlength="50" show-word-limit/>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8">
          <el-form-item label="用户操作" prop="operation" :rules="rules.isRange('1-50')">
            <el-input v-model="form.operation" placeholder="请输入用户操作" maxlength="50" show-word-limit/>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8">
          <el-form-item label="请求方法" prop="method" :rules="rules.isRange('1-200')">
            <el-input v-model="form.method" placeholder="请输入请求方法" maxlength="200" show-word-limit/>
          </el-form-item>
        </el-col>
        <el-col :xs="24" :sm="12" :md="8">
          <el-form-item label="IP地址" prop="ip" :rules="rules.isRange('1-64')">
            <el-input v-model="form.ip" placeholder="请输入IP地址" maxlength="64" show-word-limit/>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <span slot="footer" class="dialog-footer">
      <el-button @click.native="visible = false" icon="el-icon-close">取消</el-button>
      <el-button type="primary" :loading="isDisabled" icon="el-icon-check"
		  @click.native="saveOrUpdate(form, '/sysLog/save', '/sysLog/update')">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        rules: this.getRules(),
        isDisabled: false,
        form: {
          username: '',
          operation: '',
          method: '',
          params: '',
          response: '',
          ip: '',
          creator: '',
          flag: 1
        }
      }
    },
    methods: {
      init (id) {
        this.visible = true
        this.isDisabled = false
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
        this.form.id = id
        if (id) {
          this.$http({
            url: this.$http.adornUrl('/sysLog/info/' + id)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.form = data.data
            }
          })
        } else {
        }
      }
    }
  }
</script>

